/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sml;

import java.text.DecimalFormat;

/**
 *
 * @author Jose Carlos Palma
 */
public class Screen {

    private Screen() {
    }

    private static String format(String pattern, int value) {
        DecimalFormat df = new DecimalFormat(pattern);
        return df.format(value);
    }

    public static void print(Ram ram) {

        System.out.println("MEMORY:");
        System.out.print("       0     1     2     3     4     5     6     7     8     9");

        for (int i = 0; i < Ram.SIZE; i++) {
            if (i % 10 == 0) {
                System.out.print("\n" + format("00", i));
            }
            System.out.print(" " + format("+0000;-0000", ram.get(i)));
        }
        System.out.println();

    }

    public static void print(CPU cpu) {
        System.out.println("REGISTERS:");
        System.out.printf("   Accumulator: %1$5s\n", format("+0000;-0000", cpu.getAccumulator()));
        System.out.printf("       Pointer: %1$5s\n", format("00", cpu.getPointer()));
        System.out.printf("   Instruction: %1$5s\n", format("+0000;-0000", cpu.getInstruction()));
        System.out.printf("Operation Code: %1$5s\n", format("00", cpu.getOperationCode()));
        System.out.printf("       Operand: %1$5s\n\n", format("00", cpu.getOperand()));
    }
    
    public static void print(String text){
        System.out.println(text);
    }
    
    public static void print(int i){
        System.out.println(i);
    }
}
